package com.perfma.xtest.tool.word;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.BeanUtils;

import java.util.List;

/**
 * @author: junhui.si
 * @date: 2021-08-24 17:43
 **/
@NoArgsConstructor
@AllArgsConstructor
@Data
@ApiModel("（通用）统计-图表数据结构")
public class ChartDataVO2 {
    @ApiModelProperty("图表标题")
    private String title;
    @ApiModelProperty("x轴标题")
    private String xTitle;
    @ApiModelProperty("y轴标题")
    private String yTitle;
    @ApiModelProperty("x轴数据类型")
    private DataType xType;
    @ApiModelProperty("y轴数据类型")
    private DataType yType;
    @ApiModelProperty("数据")
    private List<ChartDataItemVO2> chartDataItemVO2List;

    public enum DataType {
        /**
         * 时间类型
         */
        TIMESTAMP,
        /**
         * 整数
         */
        LONG,
        /**
         * 字符串
         */
        STRING
    }

    public static ChartDataVO2 parse(ChartDataVO chartDataVO) {
        ChartDataVO2 chartDataVO2 = new ChartDataVO2();
        BeanUtils.copyProperties(chartDataVO, chartDataVO2);
        List<ChartDataItemVO> chartDataItemVOS = chartDataVO.getChartDataItemVOList();
        List<ChartDataItemVO2> List = Lists.newArrayList();
        for (ChartDataItemVO chartDataItemVO : chartDataItemVOS) {
            ChartDataItemVO2 chartDataItemVO2 = new ChartDataItemVO2();
            BeanUtils.copyProperties(chartDataItemVO, chartDataItemVO2);
            chartDataItemVO2.setPercent(Double.parseDouble(chartDataItemVO.getDesc().substring(0, chartDataItemVO.getDesc().length() - 1)) / 100);
        }
        return chartDataVO2;
    }
}
